import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.security.MessageDigest

/**
 * flow
 */
fun main()= runBlocking<Unit> {
    val map= mutableMapOf<String,String>()
    map["speaker"] = "bunny"
    map["nonce"] = "023335"
    map["ts"] = "1697183650"
    map["story_type"] = "1"
    val buffer=StringBuffer()
    map.keys.toList().sorted().map { it.lowercase() }.forEach{
        println(it)
        buffer.append("$it=${map[it]?.lowercase()}&")
    }
    val signature="7fdd7df3840cedd4610b4c17c07b5c92c687b997"
    val newBuffer= buffer.substring(0,buffer.length-1)
    val md = MessageDigest.getInstance("SHA-1")
    md.update(newBuffer.toByteArray())
    val digest = md.digest()
    val sb = StringBuilder()
    for (b in digest) {
        sb.append(String.format("%02x", b))
    }
    println(signature==sb.toString())
}
